package com.example;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.example.day02.BaseApp;
import com.example.day02.Bean;
import com.example.day02.MainActivity2;
import com.example.day02.R;
import com.example.xts.greendaodemo.db.BeanDao;

public class MainActivity3 extends AppCompatActivity implements View.OnClickListener {

    private Button mBc;
    private EditText mEdxt;
    private EditText mBq;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        initView();
    }

    private void initView() {
        mBc = (Button) findViewById(R.id.bc);
        mBc.setOnClickListener(this);
        mEdxt = (EditText) findViewById(R.id.edxt);
        mBq = (EditText) findViewById(R.id.bq);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bc:
                BeanDao beanDao = BaseApp.getInstance().getDaoSession().getBeanDao();
                String bj = mEdxt.getText().toString();
                String bq = mBq.getText().toString();
                beanDao.insert(new Bean(bj,bq));
                Intent intent = new Intent(MainActivity3.this, MainActivity2.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}
